<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, ValidatesRequests;

    public function returnJson($data = null , $message = 'success' , $httpCode = 200){
        $response = [];
        $response['message'] = $message;
        if ($data !== null) {
            $response['data'] = $data;
        }
        return response()->json($response , $httpCode);
    }

    public function returnAlreadyError($message = 'error' , $data = null){
        $json = [
            'message' => $message,
        ];
        if ($data !== null){
            $json['data'] = $data;
        }
        return response()->json($json , 409);
    }

    public function returnValidationError($message = 'error'){
        return response()->json([
            'message' => $message,
        ] , 422);
    }

    public function returnUnauthenticatedError($message = 'unauthenticated'){
        return response()->json([
            'message' => $message,
        ] , 401);
    }

    public function returnPositionError($message = 'permission denied'){
        return response()->json([
            'message' => $message,
        ] , 403);
    }

    public function returnNotFoundError($message = 'not found')
    {
        return response()->json([
            'message' => $message,
        ] , 404);
    }
}
